package atguigu.thread.excutor;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ExecutorDemo {

	public static void main(String[] args) {
		CountDownLatch latch = new CountDownLatch(3);
		ExecutorService es = new ThreadPoolExecutor(3, 10,
				10000L, TimeUnit.MILLISECONDS,
				new LinkedBlockingQueue<Runnable>(10), Executors.defaultThreadFactory(),
				new ThreadPoolExecutor.DiscardPolicy());
		for (int i = 0; i < 3; i++) {
			es.submit(()->{
				System.out.println("hello world");
			});
			latch.countDown();
		}
		try {
			latch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}finally {
			es.shutdown();
		}
	}
}
